/**
 * 功能描述
 */

define(function (require, exports, module) {
	var Grid = require("grid");
	var Dialog = require("dialog");
	var store = require("store");
	
    var instance = {
        initComponent: function (params, widget) {
        	var endGrid = new Grid({
        		parentNode: ".J-endGrid",
        		model: {
        			id:"endGrid",
        			isInitPageBar: false,
        			head : {
						buttons : [ {
							parentNode:'.J-demo',
							id : "showRoomChange",
//							type : "button",
							text : "换房记录",
							handler: function () {
						        var grid = new Grid({
						          autoRender: false,
						          model: {
						            url: 'api/checkoutsettlement/querychangeroom',
						            params: function(){
						            	return{
						            		"pkGroupReserve":widget.get("pkGroupReserve"),
				        					fetchProperties: "idNumber,name,sex,roomType,roomCode,changeRoomType,changeRoomCode,changeRoomDate"
				        				};
				        			},
				        			columns: [{
				        				name: "idNumber",
										label: "身份证号",
				        			},{
				        				name: "name",
										label: "姓名"
				        			},{
				        				name: "sex",
										label: "性别",
				        			},{
				        				name: "roomType",
										label: "房型",
										format:function(value,data){
											return data.changeRoomType;
										}
				        			},{
				        				name: "roomCode",
										label: "房号",
										format:function(value,data){
											return data.changeRoomCode;
										}
				        			},{
				        				name: "changeRoomType",
										label: "调整后房型",format:function(value,data){
											return data.roomType;
										}
				        			},{
				        				name: "changeRoomCode",
										label: "调整后房号",
										format:function(value,data){
											return data.roomCode;
										}
				        			},{
				        				name: "changeRoomDate",
										label: "调整日期",
										format: "date",
										formatparams: {
											mode: "YYYY.MM.DD"
										}
				        			}]
				        		}
						    	});
						        Dialog.showComponent(grid,{
						          //其余配置与Dialog.confirm的配置参数相同
						        });
						        grid.refresh();
						      }
						}]
					},
        			columns: [{
        				name: "room",
        				label: "房间",
        				format : function(data, row) {
        					var room = row.roomRegister.room.orgBuilding.name + row.roomRegister.room.code;
        					return room
        				}
        			},{
						name:"signUpRegister.personalInfo.name",
						label:"姓名"
					},{
						name:"signUpRegister.personalInfo.idNumber",
						label:"身份证号"
					},{
						name:"signUpRegister",
						label:"会员证号",
						format : function(data, row) {
							if(data.travelContract){
								return data.travelContract.member.personalInfo.idNumber 
									+ "-"+data.travelContract.member.personalInfo.name 
									+ "-"+data.travelContract.productRule.product.name 
									+ "-"+data.travelContract.memberCertificates;	
							}else{
								return "";
							}
						}
					},{
        				name: "payable",
        				label: "预收款",
        			},{
        				name: "liveDays",
        				label: "入住天数"
        			},{
        				name: "checkOutSettlement.sum",
        				label: "费用合计",
        				format: function(value, data) {
    		            	if(value){
    		            		return parseFloat(value).toFixed(2);	
    		            	}else{
    		            		return 0;
    		            	}
			            },
        			},{
						name:"descript",
						label:"备注",
					},{
        				name: "checkOutSettlement.balance",
        				label: "结算金额",
        				format: function(value, data) {
    		            	if(value){
    		            		return parseFloat(value).toFixed(2);	
    		            	}else{
    		            		return 0;
    		            	}
			            },
        			},{
        				name: "checkOutSettlement.checkOutSettlement",
        				label: "结算完成",
        				format: function(value,row){
        					if(value){
        						return "是"
        					}else{
        						return "否"
        					}
        				}
        			},{
        				name: "operate",
        				label: "操作",
        				format: "button",
        				formatparams: [{
        					id: "settle",
        					text: "结算",
        					show: function (value,data) {
        						if(widget.detail){
        							return false
        						}else{
        							return true
        						}
                            },
        					handler: function(index,data,rowEL){
        						widget.handler.endGrid.settle(widget,data,index,false);
        						$(".J-detailForm .J-form-form-save").removeClass("hidden");
        						$(".J-form-settleForm-save").removeClass("hidden");
        					}
        				},{
        					id: "detail",
        					text: "查看",
        					show: function (value,data) {
        						if(widget.detail){
        							return true
        						}else{
        							return false
        						}
                            },
        					handler: function(index,data,rowEL){
        						widget.handler.endGrid.settle(widget,data,index,true);
        						$(".J-detailForm .J-form-form-save").addClass("hidden");
        						$(".J-form-settleForm-save").addClass("hidden");
        					}
        				}]
        			}]
        		}
        	});
        	widget.set("endGrid",endGrid);
        }
    };
    module.exports = instance;
});
